﻿using System.Linq;
using AB.ServiceDirectory.Commons.DataFilters;
using AB.ServiceDirectory.Dao;
using AB.ServiceDirectory.Entities;

namespace AB.ServiceDirectory.BO
{
    /// <summary>
    /// ServicePremiseBO
    /// </summary>
    public sealed class ServicePremiseBO
    {
        /// <summary>
        /// Instance of ServicePremiseDao
        /// </summary>
        private static readonly ServicePremiseDao Dao = new ServicePremiseDao();

        /// <summary>
        /// Prevents a default instance of the <see cref="ServicePremiseBO"/> class from being created.
        /// </summary>
        private ServicePremiseBO()
        {
        }

        /// <summary>
        /// Gets the premise.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="sortType">Type of the sort.</param>
        /// <param name="startRowIndex">Start index of the row.</param>
        /// <param name="maxRows">The max rows.</param>
        /// <returns></returns>
        public static IQueryable GetServicePremise(ServicePremiseFilter filter, string sortType, int startRowIndex,
                                                   int maxRows)
        {
            return Dao.GetList(filter, sortType, startRowIndex, maxRows);
        }

        /// <summary>
        /// Gets the service premise count.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public static int GetServicePremiseCount(ServicePremiseFilter filter)
        {
            return Dao.GetListCount(filter);
        }

        public static bool AssociateServiceAndPremise(ServicePremise servicePremise)
        {
            return Dao.AssociateServiceAndPremise(servicePremise);
        }

        /// <summary>
        /// Removes the premise.
        /// </summary>
        /// <param name="premiseId">The premise id.</param>
        /// <param name="serviceId">The service id.</param>
        /// <returns></returns>
        public static bool RemoveAssociatedServicePremise(int serviceId, int premiseId)
        {
            var servicePremise = new ServicePremise {ServiceId = serviceId, PremiseId = premiseId};
            return Dao.RemoveAssociatedServicePremise(servicePremise);
        }
    }
}